<?php

// +----------------------------------------------------------------------
// | EasyAdmin
// +----------------------------------------------------------------------
// | PHP交流群: 763822524
// +----------------------------------------------------------------------
// | 开源协议  https://mit-license.org
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zhongshaofa/EasyAdmin
// +----------------------------------------------------------------------

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;
use think\facade\Config;
/**
 * 有关时间的模型
 * Class TimeModel
 * @package app\common\model
 */
class TimeModel extends Model
{

    /**
     * 自动时间戳类型
     * @var string
     */
    protected $autoWriteTimestamp = true;

    /**
     * 添加时间
     * @var string
     */
    protected $createTime = 'create_time';

    /**
     * 更新时间
     * @var string
     */
    protected $updateTime = 'update_time';

    /**
     * 软删除
     */
    use SoftDelete;
    protected $deleteTime = false;
    //表前缀
    public static function get_table_prefix()
    {

        return Config::get('database.connections' . '.' . config('database.default') . '.prefix');
    }
    //当前数据库
    public static function get_databasename()
    {
        return Config::get('database.connections' . '.' . Config::get('database.default') . '.database');
    }

    public static function get_addonstablename($tablename, $addon)
    {
        $tablename = str_replace($addon . '_', '', str_replace('addons_', '', $tablename));
        return $tablename = self::get_table_prefix() . 'addons_' . $addon . '_' . $tablename;
    }

}
